import { ref } from 'vue';
import { useRoute } from 'vue-router';
import {
  getProcessInstance,
  getProcessModalInfo,
  cancelProcessInstance,
} from '@/api/processInstance/index.js';

export const useProcess = () => {
  let processList = ref([]);
  const taskInfo = ref({});
  const showProcessModal = ref(false);
  const initProcess = async (processInstanceId) => {
    const res = await getProcessInstance({ processInstanceId });
    if (res.code === 200) {
      processList.value = res.data;
      if (res.data.length > 0) {
        let taskId = res.data[res.data.length - 1].id;
        let isWantFinishAudit = res.data.isWantFinishAudit;
        taskInfo.value = { taskId, isWantFinishAudit };
      }
    }
  };

  const isShowProcessModal = async (processInstanceId) => {
    const res = await getProcessModalInfo({ id: processInstanceId });
    if (res.code === 200) {
      showProcessModal.value = true;
    }
  };

  return { initProcess, processList, showProcessModal, isShowProcessModal, taskInfo };
};
